package com.example.demo.hutool.redis.monitor;

import com.example.demo.hutool.BitMap;

import java.security.NoSuchAlgorithmException;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

public class RedisCache {

    public static BitMap stringBitMap = new BitMap(1999999999);//
    public static BitMap hashBitMap = new BitMap(1999999999);//
    public static BitMap listBitMap = new BitMap(1999999999);//
    public static BitMap setBitMap = new BitMap(1999999999);//
    public static BitMap zsetBitMap = new BitMap(1999999999);//

    public static BitMap repeatStringBitMap = new BitMap(1999999999);//
    public static BitMap repeatHashBitMap = new BitMap(1999999999);//
    public static BitMap repeatListBitMap = new BitMap(1999999999);//
    public static BitMap repeatSetBitMap = new BitMap(1999999999);//
    public static BitMap repeatZsetBitMap = new BitMap(1999999999);//
    public static Set<BitMap> hashSetBitMap;

    static {
        hashSetBitMap = new HashSet<>();
        hashSetBitMap.add(stringBitMap);
        hashSetBitMap.add(hashBitMap);
        hashSetBitMap.add(listBitMap);
        hashSetBitMap.add(setBitMap);
        hashSetBitMap.add(zsetBitMap);
        hashSetBitMap.add(repeatStringBitMap);
        hashSetBitMap.add(repeatHashBitMap);

        hashSetBitMap.add(repeatListBitMap);

        hashSetBitMap.add(repeatSetBitMap);

        hashSetBitMap.add(repeatZsetBitMap);

    }


    //冲突的key
    public BitMap conflictBitMap;

    public static void main(String[] args) throws NoSuchAlgorithmException {
        //   总数:12781461   重复:40444   hashCode:1288575232
        //   总数:12481286   重复:40937   hashCode:1278402732
        BitMap bitMap = new BitMap(1999999999);
        int k = 0;
        for (int i = 0; i < 1000000; i++) {
            String s = UUID.randomUUID().toString();
            int hash = hash(s);
            if (stringBitMap.getBit(hash) == 1) {
                repeatStringBitMap.setBit(hash);
                continue;
            }
            stringBitMap.setBit(hash);
        }
        System.out.println(k);
    }

    public static void del(String key) {
        int i = hash(key);
        for (BitMap bitMap : hashSetBitMap) {

        }
    }

    static final int hash(String key) {
        long index = Math.abs((long) (key.hashCode() % 1999999999));
        return (int) index;
    }


}
